local yanjiao = fk.CreateSkill {
  name = "tyj_heg__yanjiao",
}
local H = require "packages.ol_hegemony.util"
local U = require "packages.utility.utility"
Fk:loadTranslationTable {
  ["tyj_heg__yanjiao"] = "严教",
  [":tyj_heg__yanjiao"] = "出牌阶段限一次，你可以选择一其他角色，视为使用一张仅指定你与其为目标的【以逸待劳】，若其弃置的牌类型组合与你不同，你令其获得你弃置的至少一张牌并对其造成1点伤害。",
  ["#tyj__yanjiao-choose"] = "严教：令 %dest 获得你弃置的任意张牌，并对其造成1点伤害。",

  ["$tyj_heg__yanjiao1"] = "此篇未记，会儿便不可嬉戏。",
  ["$tyj_heg__yanjiao2"] = "母亲虽严，却皆为汝好。",
  ["$tyj_heg__yanjiao3"] = "幼儿顽劣，需严加管教。<br>（严教造成伤害）",
}
yanjiao:addEffect("active", {
  anim_type = "control",
  prompt = "严教：你可以视为对你于一名其他角色使用【以逸待劳】。",
  times = function (self, player)
    return 1 - player:usedSkillTimes(yanjiao.name, Player.HistoryPhase)
  end,
  can_use = function(self, player)
    return
      player:usedSkillTimes(yanjiao.name, Player.HistoryPhase) < 1
  end,
  card_num = 0,
  card_filter = Util.FalseFunc,
  target_num = 1,
  target_filter = function(self, player, to_select, selected)
    return #selected < 1 and to_select ~= player 
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    local use = room:useVirtualCard("await_exhausted",{},player,{player,target},yanjiao.name,true)
    if use and use.extra_data and use.extra_data.tyj_heg__yanjiao_record and use.extra_data.tyj_heg__yanjiao_record[player.id] and use.extra_data.tyj_heg__yanjiao_record[target.id] and target:isAlive() and player:isAlive() then
      local mycards = use.extra_data.tyj_heg__yanjiao_record[player.id] or {}
      local tocards = use.extra_data.tyj_heg__yanjiao_record[target.id] or {}
      local mytype={}
      local damage = false
      for _, cid in ipairs(mycards ) do
        table.insert( mytype,Fk:getCardById(cid).type)
      end
      for _, cid in ipairs(tocards) do
        if table.contains(mytype,Fk:getCardById(cid).type) then
          table.removeOne(mytype,Fk:getCardById(cid).type)
        else
          damage = true
        end
      end
      if damage == true then
        local cids = table.filter(mycards, function (id)
          return table.contains(room.discard_pile, id)
        end)
        if #cids>0 then
        local c = room:askToCards(player, {
    min_num = 1,
    max_num = #cids,
    include_equip = false,
    skill_name = yanjiao.name,
    pattern = tostring(Exppattern{ id = cids }),
    prompt = "#tyj__yanjiao-choose::"..target.id,
    cancelable = false,
    expand_pile = cids,
  })
  if #c>0 then
    room:obtainCard(target, c, true, fk.ReasonJustMove, player, yanjiao.name)
  end 
end
if target:isAlive() then
  room:doIndicate(player,{target})
  player.room:notifySkillInvoked(player,yanjiao.name,"offensive")
      player:broadcastSkillInvoke(yanjiao.name,3)
room:damage {
        from = player,
        to = target,
        damage = 1,
        skillName = yanjiao.name,
      }
    end
      end
    end
  end,
})
yanjiao:addEffect(fk.AfterCardsMove,{
    can_refresh = function(self, event, target, player, data)
        for _, move in ipairs(data) do
          if move.from and move.toArea == Card.DiscardPile and move.moveReason == fk.ReasonDiscard then return true end
        end
    end,
    on_refresh = function (self, event, target, player, data)
          local e = player.room.logic:getCurrentEvent():findParent(GameEvent.UseCard,true)
          if e then
            local use = e.data
            if table.contains(use.card.skillNames, "tyj_heg__yanjiao") then
              e.data.extra_data = e.data.extra_data or {}
              local exdata = e.data.extra_data or {}
              exdata.tyj_heg__yanjiao_record = exdata.tyj_heg__yanjiao_record or {}
              for _, move in ipairs(data) do
                if move.toArea == Card.DiscardPile and move.moveReason == fk.ReasonDiscard and move.from then
                  for _, info in ipairs(move.moveInfo) do
                    exdata.tyj_heg__yanjiao_record[move.from.id] = exdata.tyj_heg__yanjiao_record[move.from.id] or {}
                    table.insertIfNeed(exdata.tyj_heg__yanjiao_record[move.from.id],info.cardId)
                  end
                end
              end
           e.data.extra_data = exdata
        end
      end
    end,
})
return yanjiao